#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct People {
	int a;
	int b; 
	int k;
};
void Order(int y[], int **order, int count)
{
	for (int i = 0; i < count; i++)
		{
			for (int j = 0; j < count; j++)
			{
				if (j == i) continue;
				if (order[j][0] == order[i][y[i]])
				{
					for (int l = 1; l <= y[j]; l++)
					{
						y[i]++;
						order[i][y[i]] = order[j][l];
					}
					j = 0;
				}
			}
		}
	for (int i = 0; i < count; i++)
		{
			for (int j = i + 1; j < count; j++)
			{
				if (y[i] < y[j])
				{
					int* temp = (int *)malloc(sizeof(int)*(count+1));
					int temp1;
					memcpy(temp, order[i],sizeof(order[i]));
					//temp = order[i];
					temp1 = y[i];
					memcpy(order[i], order[j], sizeof(order[j]));
					y[i] = y[j];
					memcpy(order[j], temp, sizeof(temp));
					y[j] = temp1;
				}
			}
		}
	for (int i = 0; i < count; i++)
		{
			if (y[i] == 0) continue;
			for (int j = i + 1; j < count; j++)
			{
				if (y[j] != 0)
				{
					int c = 0;
					for (int l = 0; l <= y[i]; l++)
					{
						if (order[j][c] == order[i][l])
						{
							c++;
							l = -1;
						}
						if (c > y[j]) break;
					}
					if (c == y[j] + 1)
					{
						for (int t = 0; t < count + 1; t++)
							order[j][t] = 0;
						y[j] = 0;
					}
				}

			}
		}
}
int Judge(int y[], int **order, int count, int m, struct People *p)
{
	for (int i = 0; i < m; i++)
	{
		if (p[i].k == 2 && p[i].a != p[i].b)
		{
			for (int j = 0; j < count; j++)
			{
				int isFlag = 0;
				if (y[j] != 0)
				{
					for (int l = 0; l <= y[j]; l++)
					{
						if (isFlag == 0)
						{
							if (p[i].a == order[j][l])
							{
								isFlag = 1;
								l = -1;
							}
						}
						else {
							if (p[i].b == order[j][l])
								return 1;
						}
					}
				}


			}
		}
	}
	return 0;
}
int main()
{
	struct People* p=NULL; 
	int x = 0;
	int count = 0;
	
	int n, m;
	int a, b, k;
	int sign=0;
	int isFlag;

	scanf("%d %d", &n, &m);

	p = (struct People*)malloc(sizeof(struct People) * m);
	for (int i = 0; i < m; i++) scanf("%d %d %d", &p[i].a, &p[i].b, &p[i].k);
	for (int i = 0; i < m; i++)
	{
		a = p[i].a;
		b = p[i].b;
		k = p[i].k;
		if (k == 1)
		{
			if (a == b) sign = 1;
			count++;
		}
	}
	if (sign == 0)
	{
		int** order;
		order = (int **)malloc(sizeof(int *)*count);
		int* y = (int *)malloc(sizeof(int)*count);

		for (int i = 0; i < count; i++) order[i] = (int *)malloc(sizeof(int)*(count*2));

		for (int i = 0; i < m; i++)
		{
		
			if (p[i].k == 1)
				{
				order[x][0] = p[i].a;
				order[x][1] = p[i].b;
				y[x] = 1;
				x++;
			}
		}
		Order(y, order, count);
	
		isFlag = Judge(y, order, count, m, p);
		if (isFlag)printf("inconsistent\n");
		else printf("consistent\n");
	}
	else printf("inconsistent\n");
	
	return 0;
}